package com.ylr.blog.framework.service.impl;

import com.ylr.base.common.po.user.UserPo;
import com.ylr.blog.framework.service.AuditBlogFlowService;
import com.ylr.base.common.utils.UserUtils;
import com.ylr.blog.framework.mapper.AuditBlogFlowMapper;
import com.ylr.base.framework.service.SnowflakeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ylr.blog.framework.entity.AuditBlogFlowEntity;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-19 20:35:33
 * className: AuditBlogFlowServiceImpl
 * version: 1.0
 * description:
 */
@Service("auditBlogFlowService")
@AllArgsConstructor
public class AuditBlogFlowServiceImpl extends ServiceImpl<AuditBlogFlowMapper, AuditBlogFlowEntity> implements AuditBlogFlowService {

    private static final Logger log = LoggerFactory.getLogger(AuditBlogFlowServiceImpl.class);

    private final SnowflakeService snowflakeService;

    @Override
    public void saveAuditBlogFlow(Long auditBlogId, Long auditUser, Integer type, String remark) {
        // 获取正在保存博客审核流水的用户
        UserPo userPo = UserUtils.getUser();
        Date date = new Date();

        AuditBlogFlowEntity auditBlogFlow = new AuditBlogFlowEntity();
        auditBlogFlow.setId(snowflakeService.getId())
                .setAuditBlogId(auditBlogId)
                .setAuditUser(auditUser)
                .setType(type)
                .setRemark(remark)
                .setCreateTime(date)
                .setCreateUser(userPo.getUsername())
                .setCreateUserId(userPo.getId());
        // 插入数据
        baseMapper.insert(auditBlogFlow);
        log.info("保存博客审核流水完成");
    }

    @Override
    public AuditBlogFlowEntity getLastOne(Long auditBlogId) {
        return baseMapper.selectLastOne(auditBlogId);
    }
}